<template>
  <view>
    <view class="mine-content flex_p_20">
      <view class="peo-info rflex ">
        <uv-avatar :text="info?.name.slice(0, 1)" fontSize="22" size="85" :randomBgColor="true" v-if="info?.name" shape="square"></uv-avatar>
        <uv-avatar size="85" src="https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/07/10/f1b911a8daad4bf7845ec75c294fdf1d.png" shape="square" v-else></uv-avatar>
        <view class="flex_w_10"></view>
        <view class="flex_1 cflex flex_x_center">
          <view class="rflex">
            <view class="name">{{info?.name}}</view>
            <view class="flex_w_8"></view>
            <uv-button type="primary" size="mini" plain v-if="info?.realName">已认证</uv-button>
            <uv-button type="error" size="mini" plain v-else>未认证</uv-button>
          </view>
          <view class="flex_h_10"></view>
          <view class="company">{{info?.companyName || '公司信息未认证'}}</view>
        </view>
      </view>
      <view class="flex_h_20"></view>
      <view class="line_lien rflex flex_y_center" v-for="item in toList" :key="item.id" @click="toDo(item)">
        <uv-avatar size="50" :src="item.url" shape="circle"></uv-avatar>
        <view class="flex_w_10"></view>
        <view class="flex_1 rflex">
          <view class="flex_2 rflex flex_y_center" style="font-size: 32rpx;font-weight: bold">{{item.text}}</view>
          <view class="flex_1 rflex flex_y_center flex_x_end">
            <i class="iconfont icon-yousanjiao"></i>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>

import UserInfoApi from "@/api/system/userInfo";
import {getUserInfoId} from "@/utils/auth";
import UserRelationApi from "@/api/user/user";

export default {
  data() {
    return {
      userId: null,
      info: {},
      toList:[
      //     {
      //   id:1,
      //   text: '去认证',
      //   url:'https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/07/12/e40b75a15f3c4c6f9da2b5e6dce0805b.png'
      // },
        {
        id:2,
        text: '我的信息',
        url:'https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/07/12/4a713aa4aefe461a824ed726e44d8f35.png'
      },
      //   {
      //   id:3,
      //   text: '邀请新用户',
      //   url:'https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/07/12/5139cd337aa346b9b5211120846d0a0b.png'
      // }
        {
          id:4,
          text: '扫一扫',
          url: 'https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/07/12/5139cd337aa346b9b5211120846d0a0b.png',
        }
      ]
    };
  },
  onShow() {
    this.userId = getUserInfoId();
    if (this.userId) {
      this.getUserInfo();
    }
  },
  methods:{
    async getUserInfo() {
      const data = await UserInfoApi.getUserProfile(this.userId);
      this.info = data?.data;
    },
    toDo(item) {
      if (item.id === 1) {
        uni.showToast( {
          icon: 'none',
          title: '功能开发中',
        })
      }else if (item.id === 2) {
        uni.navigateTo({
          url: '/page_mine/myInfo'
        })
      }else if (item.id === 3){
        uni.showToast( {
          icon: 'none',
          title: '功能开发中',
        })
      }else if (item.id === 4) {
        uni.scanCode({
          success: function (res) {
            if (res.result.indexOf('erUserId') > -1) {
              let arr = res.result.split(':');
              const data = {
                userId: arr[1],
              };
              UserRelationApi.addRelation(data).then(res => {
                uni.showToast({
                  icon: 'none',
                  title: '扫码握手成功！',
                });
              });
            } else {
              uni.showToast({
                icon: 'none',
                title: '请扫小程序生成的个人二维码！',
              });
            }
          },
          fail: function (res) {
            uni.showToast({
              icon: 'error',
              title: '二维码错误！',
            });
          },
        })
      }
    },
  }
}
</script>
<style>
page{
  background: #f5f5f5;
}
</style>
<style scoped lang="scss">
.mine-content{
  width: 100vw;
  height: 100vh;
  background: url("https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/07/11/0cc0e080a0964615b31a9de37cb5052a.png") no-repeat;
  background-size: 100% 100%;
  .peo-info{
    .name{
      font-size: 36rpx;
      font-weight: bold;
    }
    .company{
      color: grey;
    }
  }
  .line_lien{
    padding-top: 5px;
    padding-bottom: 5px;
    border-bottom: 1px solid #fff;
  }
}
</style>
